import React from "react"

import { Route, Redirect } from "react-router-dom";


function AuthRoute({ component: Component, ...rest }) {
  return (
    <Route
      {...rest}
      render={(props) => {
        //   路由守卫
        let token = localStorage.getItem("token"); //简易拦截
        let to = "";
        if (token) {
          to = <Component {...props} />;
        } else {
          to = (
            <Redirect
              to={{
                pathname: "/login",
                state: { from: props.location },
              }}
            />
          );
        }
        return to;
      }}
    />
  );
}

export default AuthRoute

